package com.swfee.qinben.session;

import com.swfee.qinben.dto.rsp.LoginRspDto;

public class UserSession {


	private static UserSession instance = new UserSession();
	
	private LoginRspDto loginRspDto;
	

	private UserSession() {

	}

	public static boolean isLogined(){
		return instance!=null && instance.loginRspDto !=null;
	}
	public static void init(LoginRspDto loginRspDto) {
		if (instance == null) {
			instance = new UserSession();
		}
		if(loginRspDto!=null){
			instance.loginRspDto = loginRspDto;
		}
	}
	
	
	public static Integer getUserId(){
		return instance.loginRspDto.getUserId();
	}
	
	public static String getName() {
		return instance.loginRspDto.getName();
	}
	public static String getAppCode() {
		return instance.loginRspDto.getAppCode();
	}

	public static LoginRspDto getLoginRspDto() {
		return instance.loginRspDto;
	}
	
	public static String getRoleCode() {
		return instance.loginRspDto.getRoleCode();
	}
	
	/**
	 * 1. DOCTOR 2. USER 3. NURSE
	 * @return
	 */
	public static int getRoleType(){
		
		String roleUp = (instance.loginRspDto.getRoleCode()).toUpperCase();
		if(roleUp.equals("DOCTOR")){
			return 1;
		}
		else if(roleUp.equals("USER")){
			return 2;
		}
		else if(roleUp.equals("NURSE")){
			return 3;
		}
		return -1;
	}
	
	public static boolean isNurse(){
		return getRoleType() == 3;
	}
	public static boolean isDoctor(){
		return getRoleType() == 1;
	}
	public static boolean isUser(){
		return getRoleType() == 2;
	}
	
	
	
	
	

}
